class MsgModel {
  final int code;
  final String msg;
  final List<MsgOrderModel> msgList;

  MsgModel({
    required this.code,
    required this.msg,
    required this.msgList,
  });

  factory MsgModel.fromJson(Map<String, dynamic> json) {
    var data = json['data'];
    List<MsgOrderModel> msgList = [];

    if (data != null) {
      // 获取 orderMsg 和 promotionMsg
      var orderMsgData = data['orderMsg'];
      var promotionMsgData = data['promotionMsg'];

      // 如果 orderMsg 的 msg 字段非空，则添加到 msgList 中
      if (orderMsgData != null && orderMsgData['msg']?.isNotEmpty == true) {
        var orderMsg = MsgOrderModel.fromJson(orderMsgData);
        orderMsg.stype = 0;  // `stype` 为 0
        msgList.add(orderMsg);
      }

      // 如果 promotionMsg 的 msg 字段非空，则添加到 msgList 中
      if (promotionMsgData != null && promotionMsgData['msg']?.isNotEmpty == true) {
        var promotionMsg = MsgOrderModel.fromJson(promotionMsgData);
        promotionMsg.stype = 1;  // `stype` 为 1
        msgList.add(promotionMsg);
      }
    }

    return MsgModel(
      code: json['code'],
      msg: json['msg'],
      msgList: msgList,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'msg': msg,
      'msgList': msgList.map((e) => e.toJson()).toList(),
    };
  }
}

class MsgOrderModel {
  final int count;
  final String msg;
  final String time;
  int stype;

  MsgOrderModel({
    required this.count,
    required this.msg,
    required this.time,
    this.stype = 0,
  });

  factory MsgOrderModel.fromJson(Map<String, dynamic> json) {
    return MsgOrderModel(
      count: json['count'] ?? 0,
      msg: json['msg'] ?? '',
      time: json['time'] ?? '',
      stype: json['stype'] ?? 0,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'count': count,
      'msg': msg,
      'time': time,
      'stype': stype,
    };
  }
}

class AreaCodeModel {
  final String value;
  final String label;
  final String name;

  AreaCodeModel({
    required this.value,
    required this.label,
    required this.name,
  });
  factory AreaCodeModel.fromJson(Map<String, dynamic> json) {
    return AreaCodeModel(
      value: json['value']?? '',
      label: json['label']?? '',
      name: json['name']?? '',
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'value': value,
      'label': label,
      'name': name,
    };
  } 
}

class CheckModel {
  int code = 0;
  String msg = '';
  CheckDataModel? data;

  CheckModel();

  CheckModel.fromJson(Map<String, dynamic> json) {
    code = json['code'] ?? 0;
    msg = json['msg'] ?? '';
    data = json['data'] != null ? CheckDataModel.fromJson(json['data']) : null;
  }
}

class CheckDataModel {
  String avatarThumb = '';
  String nickName = '';
  String tiktokId = '';

  CheckDataModel();

  CheckDataModel.fromJson(Map<String, dynamic> json) {
    avatarThumb = json['avatarThumb'] ?? '';
    nickName = json['nickName'] ?? '';
    tiktokId = json['tiktokId'] ?? '';
  }
}

